function mypAjax(method, url) {
    return new Promise((resolve, reject) => {
        let xhr1 = new XMLHttpRequest();
        xhr1.open(method, url);
        xhr1.send();
        xhr1.onreadystatechange = function () {
            if (this.readyState === 4) {
                if (this.status === 200) {
                    resolve(JSON.parse(this.responseText));
                } else {
                    reject(new error(`请求失败!${this.status}`))
                }
            }
        }
    })
}

mypAjax('get', `http://39.105.198.203:3001/prod/index`).then(res => {
    let pic = $('<div></div>')
    pic.html(`
                <img class="pic" src="${res.data.banner}" alt="">
                `)
    $('.topPic').append(pic);
    console.log(res.data.list);
    res.data.list.forEach(function (item, index) {
        let li = $(' <li class="li"></li>')
        li.html(`
                         <a href='./detailpages.html?id=${item.tid}'>
                         <div class="contentBox">
                                <div>
                                    <img class="smPic" src="${item.fullSrc}" alt="">
                                </div>
                                <div class="text">
                                    <p>${item.tname}</p>
                                    <span class="fuhao">￥ <span class="price">${item.price}</span></span>
                                </div>
                            </div>
                         </a>    
                    `)
        $('.list').append(li);
    })
        (reason) => {
        //请求失败
        alert(reason.msg)
    }
})

